/**
 * @author LARAKI Meryem, MATHIEU Renaud
 * <h1>ESIAL 2A - PIDR 2010 </h1>
 * <h2>Modelisation de connaissances et competences informatiques</h2>
 */

package graphique;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;

import javax.swing.BorderFactory;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.TitledBorder;

import modele.Parser;

import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;

import uk.ac.manchester.cs.owl.owlapi.OWLNamedIndividualImpl;

public class VueAfficherEsialiens extends JPanel {
	
	private static final long serialVersionUID = 1L;
	// --------------------
	// Attributs
	// --------------------
	public Parser parser;
	public JList liste;

	// --------------------
	// Constructeur
	// --------------------
	public VueAfficherEsialiens(Parser parser) {
		this.parser = parser;

		OWLClass esial = parser.instanceClasse("http://www.owl-ontologies.com/Ontology1269438469.owl#ESIAL");

		// Creation des elements graphiques
		liste = new JList();
		liste.setModel(new ListIndividusAdapter(parser.getArrayIndividus(esial)));
		liste.setCellRenderer(new ListIndividusFormater());

		// Ajout des elements graphiques
		this.add(new JScrollPane(liste));
		
		// Ajout des actions
		liste.addMouseListener(new ActionClick(this.parser));

		// Options du JPanel
		TitledBorder afact = BorderFactory.createTitledBorder("ESIAL");
		afact.setTitleJustification(TitledBorder.CENTER);
		setBorder(afact);
	}// cons-1

	// --------------------
	// Methodes
	// --------------------
	private class ActionClick extends MouseAdapter{

		private Parser parser;
		
		public ActionClick(Parser parser){
			this.parser = parser;
		}
		
		public void mousePressed(MouseEvent e) {
			
			if (e.getClickCount() == 2) {
				String msg = "";
				
				ArrayList<OWLObjectPropertyExpression> lesProprietes = parser.getProprietesFromIndividu((OWLNamedIndividualImpl)liste.getSelectedValue());
				for(int i = 0 ; i < lesProprietes.size() ; i++){
					String tmp = lesProprietes.get(i).toString();
					tmp = tmp.split("#")[1];
					msg += tmp.substring(0, tmp.length()-1)+"\n";
				}
				
				JOptionPane.showMessageDialog(null, msg,"Proprietes de l'individu",JOptionPane.INFORMATION_MESSAGE);
			}
		}
	}
	
	
}
